package com.vic.work_queues;

import com.rabbitmq.client.Channel;
import com.vic.utils.RabbitmqUtils;

import java.nio.charset.StandardCharsets;

/**
 * 发送者
 */
public class Producer {

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitmqUtils.getChannel();

        // 声明队列
        /**
         * 各参数的说明，请参考Technology/RabbitMQ/rabbitmq系列
         */
        channel.queueDeclare(Consts.QUEUE_NAME, false, false, false , null);

        // 从控制台接收消息
        /*Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()) {
            String msg = scanner.next();
            // 发送消息
            channel.basicPublish("", Consts.QUEUE_NAME, null, msg.getBytes(StandardCharsets.UTF_8));
            System.out.println("发送消息完成: " + msg);
        }*/

        for (int i = 1; i <= 10; i++) {
            channel.basicPublish("", Consts.QUEUE_NAME, null, ("好消息" + i).getBytes(StandardCharsets.UTF_8));
        }
        System.out.println("发送消息完成");

    }

}
